public class Solution {
    public int peakIndexInMountainArray(int[] arr) {
        int left = 1;
        int right = arr.length - 2;
        while(left < right) {
            int mid = left + (right - left + 1) / 2;
            if(arr[mid] > arr[mid - 1]) {
                left = mid;
            } else {
                right = mid - 1;
            }
        }
        return left;
    }
    public int findMin(int[] nums) {
        int left = 0;
        int right = nums.length - 1;
        int cmp = nums[right];
        while(left < right) {
            int cmd = (left + right ) / 2;
            if(nums[cmd] > cmp) {
                left = cmd + 1;
            } else {
                right = cmd;
            }
        }
        return nums[left];
    }
    public int findPeakElement(int[] nums) {
        int left = 0;
        int right = nums.length - 1;
        if(right < 1) {
            return 0;
        }
        while(left < right) {
            int cmd = (left + right + 1) / 2;
            if(nums[cmd -1] <= nums[cmd] ) {
                left = cmd;
            } else {
                right = cmd -1;
            }
        }
        return left;
    }
    public int missingNumber(int[] nums) {
        int left = 0;
        int right = nums.length - 1;
        while(left < right) {
            int mid = left + (right - left) / 2;
            if(nums[mid] == mid) {
                left = mid + 1;
            } else {
                right = mid;
            }
        }
        return left == nums[left] ? left + 1 : left;
    }
}
